import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { PageId } from '@/stores/interfaces/list.interface'

interface Params {
  category?: keyof typeof PageId
  uuid?: number
}

export function usePageId() {
  const route = useRoute()

  const pageId = computed(() => {
    const { uuid, category = 'home' } = route.params as Params
    return +(uuid ?? PageId[category])
  })

  return { pageId }
}

export function stringToPageId(str: string) {
  return PageId?.[str as keyof typeof PageId] ?? 0
}
